package org.deadline.model.baseapp;

import flexjson.JSONDeserializer;
import flexjson.JSONSerializer;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.deadline.model.config.Enumeration;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;

@Entity
public class CommunicationChannel extends BaseEntity  implements Serializable {

    @ManyToOne
    private Enumeration communicationType;

    @NotNull
    @Size(min = 3, max = 30)
    private String configValues;

    @Size(min = 3, max = 30)
    private String areaCode;

    @Size(min = 3, max = 30)
    private String countryCode;

    @Size(min = 3, max = 30)
    private String extension;

    @ManyToOne
    private Enumeration provider;

    @NotNull
    private boolean primaryContact;

    @ManyToOne
    private Principal principal;

    @ManyToOne
    private Address address;

	@Id
	@Column(name="id",unique=true,nullable=false)
	@SequenceGenerator(name="communication_channel_seq_gen",sequenceName="communication_channel_seq")
	@GeneratedValue(generator="communication_channel_seq_gen",strategy=GenerationType.TABLE)
	@Generated(GenerationTime.INSERT)
	private Long id;

	
	public String toString() {
        return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }

	public String toJson() {
        return new JSONSerializer().exclude("*.class").deepSerialize(this);
    }

	public static CommunicationChannel fromJsonToCommunicationChannel(String json) {
        return new JSONDeserializer<CommunicationChannel>().use(null, CommunicationChannel.class).deserialize(json);
    }

	public static String toJsonArray(Collection<CommunicationChannel> collection) {
        return new JSONSerializer().exclude("*.class").deepSerialize(collection);
    }

	public static Collection<CommunicationChannel> fromJsonArrayToCommunicationChannels(String json) {
        return new JSONDeserializer<List<CommunicationChannel>>().use(null, ArrayList.class).use("values", CommunicationChannel.class).deserialize(json);
    }

	public Enumeration getCommunicationType() {
        return this.communicationType;
    }

	public void setCommunicationType(Enumeration communicationType) {
        this.communicationType = communicationType;
    }

	public String getConfigValues() {
        return this.configValues;
    }

	public void setConfigValues(String configValues) {
        this.configValues = configValues;
    }

	public String getAreaCode() {
        return this.areaCode;
    }

	public void setAreaCode(String areaCode) {
        this.areaCode = areaCode;
    }

	public String getCountryCode() {
        return this.countryCode;
    }

	public void setCountryCode(String countryCode) {
        this.countryCode = countryCode;
    }

	public String getExtension() {
        return this.extension;
    }

	public void setExtension(String extension) {
        this.extension = extension;
    }

	public Enumeration getProvider() {
        return this.provider;
    }

	public void setProvider(Enumeration provider) {
        this.provider = provider;
    }

	public boolean isPrimaryContact() {
        return this.primaryContact;
    }

	public void setPrimaryContact(boolean primaryContact) {
        this.primaryContact = primaryContact;
    }

	public Principal getPrincipal() {
        return this.principal;
    }

	public void setPrincipal(Principal principal) {
        this.principal = principal;
    }

	public Address getAddress() {
        return this.address;
    }

	public void setAddress(Address address) {
        this.address = address;
    }

	
	public Long getId() {
	    return this.id;
	}

	public void setId(Long id) {
	    this.id = id;
	}


	private static final long serialVersionUID = 1L;
}
